package com.gitee.wsl.net.server.health

data class Check(val checkName: String, val check: CheckFunction)

typealias CheckFunction = suspend () -> Boolean

/**
 * A builder class used to create descriptive DSL for adding checks to an endpoint.
 * @see healthChecks
 * @see readyChecks
 */
class CheckBuilder {
    val checks = linkedSetOf<Check>()

    /**
     * A custom check that will be run on every call the customized endpoint.
     * If any check [CheckFunction] returns false, a 500 will be returned.
     * @param name The name of the check in the GET response
     * @param check A boolean returning function that supplies the result of the check
     */
    fun check(name: String, check: CheckFunction) {
        checks.add(Check(name, check))
    }
}